#!/usr/bin/env python3
"""
账号密码检测功能
允许用户最多输入3次账号密码，检测是否正确
"""

def account_login():
    """
    账号登录检测功能
    
    功能描述：
    - 预设正确的账号密码
    - 允许用户最多有3次输入机会
    - 输入正确显示"登录成功"
    - 输入错误显示"用户名或密码错误"和剩余次数
    - 超过3次错误显示"输入错误次数过多多，请稍后再试"
    """
    # 预设-设正确的账号密码
    CORRECT_USERNAME = "admin"
    CORRECT_PASSWORD = "123456"
    
    # 最大尝试次数
    MAX_attempts = 3
    attempts = 0
    
    print("=" * 30)
    print("账号登录系统")
    print("=" * 30)
    
    # 使用while循环控制登录尝试
    while attempts < max_attempts:
        # 计算剩余尝试次数
        remaining_attempts = max_attempts - attempts
        
        # 获取用户输入
        username = input(f"\n请输入用户名（还有{remaining_attempts}次机会）：")
        password = input("请输入密码：")
        
        # 验证账号密码
        if username == CORRECT_USERNAME and password == CORRECT_PASSWORD:
            print("\n" + "=" * 30)
            print("登录成功！")
            print("=" * 30)
            return True
        else:
            attempts += 1
            remaining_attempts = max_attempts - attempts
            
            if remaining_attempts > 0:
                print(f"\n用户名或密码错误！还有{remaining_attempts}次机会。")
            else:
                print("\n" + "=" * 30)
                print("输入错误次数过多多，请稍后再试。")
                print("=" * 30)
    
    return False

def account_login_with_feedback():
    """
    带详细反馈的账号登录检测功能
    
    功能描述：
    - 预设正确的账号密码
    - 用户最多有3次输入机会
    - 提供更详细的错误反馈
    - 输入正确显示欢迎信息
    """
    # 预设正确的账号密码
    CORRECT_USERNAME = "user123"
    CORRECT_PASSWORD = "pass456"
    
    print("=" * 35)
    print("高级账号登录系统")
    print("=" * 35)
    
    attempts = 0
    max_attempts = 3
    
    while attempts < max_attempts:
        remaining = max_attempts - attempts
        print(f"\n【第{attempts + 1}次尝试，剩余{remaining}次机会】")
        
        username = input("用户名：").strip()
        password = input("密码：").strip()
        
        # 检查输入是否为空
        if not username or not password:
            attempts += 1
            print("错误：用户名和密码不能为空！")
            continue
        
        # 验证账号密码
        if username == CORRECT_USERNAME and password == CORRECT_PASSWORD:
            print("\n" + "=" * 35)
            print(f"欢迎回来，{username}！")
            print("登录成功，正在加载系统...")
            print("=" * 35)
            return True
        else:
            attempts += 1
            remaining = max_attempts - attempts
            
            # 提供更详细的错误信息
            if username != CORRECT_USERNAME and password != CORRECT_PASSWORD:
                print(f"错误：用户名和密码都不正确！")
            elif username != CORRECT_USERNAME:
                print(f"错误：用户名不正确！")
            else:
                print(f"错误：密码不正确！")
            
            if remaining > 0:
                print(f"请重新输入，还有{remaining}次机会。")
            else:
                print("\n" + "=" * 35)
                print("登录失败：错误次数过多")
                print("您的账号已临时锁定，请10分钟后再试")
                print("=" * 35)
    
    return False

def main():
    """主函数"""
    print("账号密码检测功能演示")
    print("=" * 40)
    
    print("\n1. 基础版登录系统")
    print("2. 高级版登录系统（带详细反馈）")
    
    choice = input("\n请选择要演示的版本 (1/2)：")
    
    if choice == "1":
        account_login()
    elif choice == "2":
        account_login_with_feedback()
    else:
        print("无效选择，默认演示基础版登录系统")
        account_login()

if __name__ == "__main__":
    main()
